<div class="row">
    <div class="col-sm-20">
        <h1 class="pagetitle"><span translate lib="web">detailsfor</span> {{ctrl.model.name}}</h1>
    </div>
</div>
<style type="text/css">
    .list-group-item:hover {
        color: #337ab7;
        text-shadow: 0 0 1em #337ab7;
        cursor: pointer;
    }

    .listgroupitemselected {
        border: 6px;
        border-color: black;
        background-color: #337ab7;
        color: white;
        cursor: pointer;
    }

    textarea {
        border: 0 none white;
        overflow: hidden;
        padding: 0;
        outline: none;
        background-color: #D0D0D0;
    }

    textarea.form-control {
        min-height: unset !important;
    }
    .secret {
        -webkit-text-security: disc;
    }
</style>

<button ng-click="showPerm = !showPerm" class="btn ">Access Control List</button>
<div ng-show="showPerm">
    <div class="form-inline">
        <label for="add" class="col-sm-1 control-label" translate lib="web">add</label>
        <div class="col-sm-6 input-group" id="addusergroup">
            <input type="text" name="user" id="user" ng-model="ctrl.searchtext" ng-keyup="ctrl.setkey($event)"
                class="form-control" ng-model-options="{ debounce: 500 }" ng-change="ctrl.handlefilter()"
                ng-keypress="ctrl.restrictInput($event)" autocomplete="off" />
            <button ng-click="ctrl.adduser()" type="button"
                ng-disabled="ctrl.loading==true || ctrl.searchSelectedItem==null" class="btn btn-success " translate
                lib="web">add</button>
        </div>
    </div>
    <div>
        <div class="col-sm-2"></div>
        <div class="col-sm-6">
            <ul class="list-group">
                <li class="list-group-item" ng-repeat="item in ctrl.searchFilteredList"
                    ng-click="ctrl.fillTextbox(item.name)"
                    ng-class="{listgroupitemselected: ctrl.searchSelectedItem._id==item._id}">
                    ({{item._type}}) {{item.name}} <span ng-show="item.name != item.username">{{" " + item.username}}</span>
                </li>
            </ul>
        </div>
    </div>
    
    
    <section ng-repeat="ace in ctrl.model._acl" ng-show="ctrl.collection!='files'" id="entitypermissions">
        <!-- make a look like normal text and not links -->
        <div class="form-inline">
            <label class="col-sm-4 control-label">{{ace.name}}: </label>
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 1)"
                ng-click="ctrl.toogleBit(ace, 1)" value="1" id="{{ace._id}}" /> <span ng-click="ctrl.toogleBit(ace, 1)">create</span>
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 2)"
                ng-click="ctrl.toogleBit(ace, 2)" value="2" id="{{ace._id}}" /> <span ng-click="ctrl.toogleBit(ace, 2)">read</span>
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 3)"
                ng-click="ctrl.toogleBit(ace, 3)" value="3" id="{{ace._id}}" /> <span ng-click="ctrl.toogleBit(ace, 3)">update</span>
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 4)"
                ng-click="ctrl.toogleBit(ace, 4)" value="4" id="{{ace._id}}" /> <span ng-click="ctrl.toogleBit(ace, 4)">delete</span>
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 5)"
                ng-click="ctrl.toogleBit(ace, 5)" value="5" id="{{ace._id}}" /> <span ng-click="ctrl.toogleBit(ace, 5)">invoke</span>
            <button type="button" ng-click="ctrl.removeuser(ace._id)" ng-disabled="ctrl.loading" translate
                lib="web">delete</button>
        </div>
    </section>
    <section ng-repeat="ace in ctrl.model.metadata._acl" ng-show="ctrl.collection=='files'">
        <div class="form-group">
            <div class="col-sm-9 input-group">
                <label class="col-sm-3 control-label">{{ace.name}}: </label>
                <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 1)"
                    ng-click="ctrl.toogleBit(ace, 1)" value="1" id="{{ace._id}}" /> create
                <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 2)"
                    ng-click="ctrl.toogleBit(ace, 2)" value="2" id="{{ace._id}}" /> read
                <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 3)"
                    ng-click="ctrl.toogleBit(ace, 3)" value="3" id="{{ace._id}}" /> update
                <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 4)"
                    ng-click="ctrl.toogleBit(ace, 4)" value="4" id="{{ace._id}}" /> delete
                <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace, 5)"
                    ng-click="ctrl.toogleBit(ace, 5)" value="5" id="{{ace._id}}" /> invoke
                <button type="button" ng-click="ctrl.removeuser(ace._id)" ng-disabled="ctrl.loading" translate
                    lib="web">delete</button>
            </div>
        </div>
    </section>
</div>



<pre ng-show="ErrorMessage!=null" class=" alert alert-danger" role="alert">{{ ErrorMessage }}</pre>
<div ng-show="ctrl.errormessage != ''"" class=" alert alert-danger" role="alert">{{ctrl.errormessage}}</div>
<pre>{{ctrl.message}}</pre>
<a href="" ng-hide="ctrl.showjson==true" ng-click="ctrl.togglejson()" translate lib="web"
    id="enableshowjson">showjson</a>
<a href="" ng-hide="ctrl.showjson==false" ng-click="ctrl.togglejson()" translate lib="web">showproperties</a>
<form ng-submit="ctrl.submit()" class="form-inline" role="form" autocomplete="off" ng-hide="ctrl.showjson==true">
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" ng-disabled="ctrl.loading==true" class="btn btn-success" translate
                lib="web">save</button>
        </div>
    </div>
    <div class="form-group">
        <label><span translate lib="web">name</span></label>
        <input type="text" ng-class="{'form-control': true}" ng-model="ctrl.model.name" />
    </div>
    <div class="form-group" ng-show="menuctrl.hasrole('admins')">
        <label><span translate lib="web">type</span></label>
        <input type="text" ng-class="{'form-control': true}" ng-model="ctrl.model._type" />
        </div>
    <div ng-repeat="key in ctrl.keys" class="form-group" ng-show="!ctrl.isobject(ctrl.model[key]) && key != 'name'">
        <label>{{ key }}</label>
        <!-- no-model does not work for boolens if type has not been set before parsing ng-type -->
        
        <input ng-model="ctrl.model[key]" ng-if="ctrl.gettype(ctrl.model[key]) != 'boolean'"
            ng-model="ctrl.model[key]"
            ng-type step="{{ctrl.getstep(key, ctrl.model[key])}}"
            ng-class="{'form-control': ctrl.gettype(ctrl.model[key]) != 'boolean', 'secret': ctrl.model._encrypt.indexOf(key) > -1}" />
        <input ng-model="ctrl.model[key]" ng-if="ctrl.gettype(ctrl.model[key]) == 'boolean'"
        type="checkbox" ng-model="ctrl.model[key]"
        ng-type step="{{ctrl.getstep(key, ctrl.model[key])}}"
        ng-class="{'form-control': ctrl.gettype(ctrl.model[key]) != 'boolean', 'secret': ctrl.model._encrypt.indexOf(key) > -1}" />
    </div>
    <div ng-repeat="key in ctrl.keys" class="form-group" ng-show="ctrl.isobject(ctrl.model[key])">
        <label>{{ key }}</label>
        <textarea json-text class='form-control' rows='1' data-min-rows='1' ng-model="ctrl.model[key]"></textarea>
    </div>
    <div class="form-inline">
        <label class="col-sm-2 control-label" translate lib="web">add key</label>
        <div class="col-sm-4">
            <input type="text" class='form-control' ng-model="ctrl.newkey"></input>
        </div>
        <div class="col-sm-2">
            <button ng-click="ctrl.addkey()" type="button" ng-disabled="ctrl.loading==true" class="btn btn-success"
                translate lib="web">add</button>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" ng-disabled="ctrl.loading==true" class="btn btn-success" translate
                lib="web">save</button>
        </div>
    </div>
</form>

<form ng-submit="ctrl.submit()" class="form-horizontal" role="form" autocomplete="off" ng-hide="ctrl.showjson==false">
    <div ng-hide="ctrl.showjson==false" class="form-group" style="width: 100%;">
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-9">
                <button type="submit" ng-disabled="ctrl.loading==true" class="btn btn-success" translate
                    lib="web">save</button>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" translate lib="web">json</label>
            <div class="col-sm-9">
                <!-- <textarea class="form-control" rows="5" ng-model="ctrl.jsonmodel" style="max-width: 100%;"></textarea> -->

                <textarea class=' form-control' rows='3' data-min-rows='3' ng-model="ctrl.jsonmodel"></textarea>

                <!-- <textarea msd-elastic  class="form-control" ></textarea> -->
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-9">
                <button type="submit" ng-disabled="ctrl.loading==true" class="btn btn-success" translate
                    lib="web">save</button>
            </div>
        </div>
    </div>
</form>